﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Common;
using MySql.Data.MySqlClient;
using Model;

namespace DAL
{
    public class SOP_AppInstallDAL
    {
        /// <summary>
        /// 获取安装包
        /// </summary>
        /// <param name="BossID"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public IList<SOP_AppInstall> GetAppInstallList(string BossID, string AppType)
        {
            IList<SOP_AppInstall> _getlist = new List<SOP_AppInstall>();

            using (MySqlConnection conn = DAL.SqlHelper.Settings.GetSOPMySqlConnection(false))
            {
                try
                {
                    MySqlCommand cmd = new MySqlCommand("P_GetAppInstallByBossID_MZ", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@BossID_Para", MySqlDbType.VarChar, 20).Value = BossID;
                    cmd.Parameters.Add("@AppType_Para", MySqlDbType.VarChar, 20).Value = AppType;
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    MySqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (sdr != null)
                    {
                        while (sdr.Read())
                        {
                            SOP_AppInstall Ent = new SOP_AppInstall();
                            Ent.ID = Convert.ToInt32(sdr["ID"].ToString());
                            Ent.BossID = sdr["BossID"].ToString();
                            if (!string.IsNullOrWhiteSpace(sdr["AppID"].ToString()))
                                Ent.AppID = Convert.ToInt32(sdr["AppID"].ToString());
                            Ent.AppInstallURL = sdr["AppInstallURL"].ToString();
                            _getlist.Add(Ent);
                        }
                    }
                }
                catch
                {
                    return null;
                }
                finally
                {
                    conn.Close();
                }
            }

            return _getlist;
        }
    }
}
